package com.ibeetl.cms.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.ibeetl.admin.console.web.dto.SiteExcelImportData;
import org.beetl.sql.core.engine.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ibeetl.admin.core.util.PlatformException;

import com.ibeetl.cms.dao.SiteDao;
import com.ibeetl.cms.entity.Site;
import com.ibeetl.admin.core.service.BaseService;

/**
 * 博士后站点配置 Service
 */

@Service
@Transactional
public class SiteService extends BaseService<Site>{

    @Autowired
    private SiteDao siteDao;

    public PageQuery<Site>queryByCondition(PageQuery query){
        PageQuery ret =  siteDao.queryByCondition(query);
        queryListAfter(ret.getList());
        return ret;
    }

    public void batchDelSite(List<Long> ids){
        try {
            siteDao.batchDelSiteByIds(ids);
        } catch (Exception e) {
            throw new PlatformException("批量删除博士后站点配置失败", e);
        }
    }

    public void batchInsert(List<SiteExcelImportData> list) {
        final Map<Integer,SiteExcelImportData> map = new HashMap<>();
        //逐个按照顺序导入
        for(SiteExcelImportData item:list) {
            Site dict = new  Site();
            dict.setApprovalNumber(item.getApprovalNumber());
            dict.setWorkstationName(item.getWorkstationName());
            dict.setTimeConstruction(item.getTimeConstruction());
            dict.setState(item.getState());
            siteDao.insert(dict);
        }}

    public void invalid(List<Long> ids){
        try {
            siteDao.invalid(ids);
        } catch (Exception e) {
            throw new PlatformException("批量失效失败", e);
        }
    }
}